﻿namespace NuGetCop.MSBuild.Tasks.Configuration.Readers
{
    using System.Diagnostics.Contracts;
    using System.Xml;
    using System.Xml.Serialization;
    using NuGetCop.MSBuild.Tasks.Configuration.Schema;

    internal sealed class NuGetCopSettingsXmlReader : INuGetCopSettingsReader<XmlReader>
    {
        private static readonly XmlSerializer Serializer =
            new XmlSerializer(typeof(NuGetCopSettings), SchemaSpecification.Namespace);

        public NuGetCopSettings ReadSettings(XmlReader source)
        {
            var resultSettings = Serializer.Deserialize(source);
            Contract.Assert(resultSettings is NuGetCopSettings);

            return (NuGetCopSettings)resultSettings;
        }
    }
}
